<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>新品有戏后台管理</title>
    <link href="__CSS__/boot.css" rel="stylesheet">
    <link href="__STATIC__/layui/css/layui.css" rel="stylesheet">
    <script src="__JS__/jquery.js"></script>
    <script src="__JS__/layer/layer.js"></script>
    <script src="__STATIC__/layui/layui.js"></script>
    <style>
        tr,td{
            text-align: center;
            vertical-align: middle!important;
        }
    </style>
</head>
<body>
{include file="base/header" /}
<div style="float: right; margin-top: 5px;margin-bottom: 5px" class="box-title ">
    <form class="form-inline" action="{:url('index/postbusiness/product')}" method="get">
        <input type="hidden" name="bid" value="{$bid}">
        <input type="hidden" name="sid" value="{$sid}">
        <input type="text" placeholder="商品名称" name="title" value="<?php if(isset($title)) echo $title ?>" class="form-control" id="exampleInputEmail3" >
        <input type="submit" class="btn btn-default" value="搜索"/>
        <input type="button" onclick="res({$bid},{$sid})" value="全部显示" class="btn btn-default"/>
    </form>
</div>
<table  class="layui-table" id="test_table" >
    <thead>
    <tr>
        <td style="display: none">产品id</td>
        <td>产品名</td>
        <td>操作</td>
    </tr>
    </thead>
    <tbody>
    {foreach $result as $val}
        <tr>
            <td style="display: none">{$val.pid}</td>
            <td>{$val.pname}</td>
            <td>
                <button type="button" onclick="detail({$val.pid},{$bid},{$sid})" class="btn btn-primary btn-xs">详情</button>
            </td>
        </tr>
    {/foreach}
    </tbody>
</table>
{$result->render()}
<form style="display: none" id="form1" action="{:url('index/postbusiness/settlement')}" method="post">
    <input type="text" name="sid" value="{$sid}">
    <input type="text" name="bid" value="{$bid}">
    <input type="text" name="all" value="">
</form>
</body>
<script>
    //去结算
    function sellnumber(sid,bid) {
        var box = $("input[name=check]:checked").val();
        if(!box){
            layer.alert('请选择需要结算的订单');
            return;
        }
        var all = [];
        var rows = document.getElementById("test_table").rows;
        var check = document.getElementsByName("check");
        var  table = document.getElementById("test_table");
        for(var i=0;i<check.length;i++)
        {
            var single = [];
            if(check[i].checked){
                var row = check[i].parentElement.parentElement.rowIndex;
                single.push(rows[row].cells[1].innerHTML);
                single.push(rows[row].cells[2].innerHTML);
                single.push(rows[row].cells[3].innerHTML);
                single.push(rows[row].cells[4].innerHTML);
                single.push(rows[row].cells[5].innerHTML);
                single.push(rows[row].cells[6].innerHTML);

            }
            if(single.length != 0)
            {
                all.push(single);
            }
        }
        var data = arrayToJson(all);
        $("input[name=all]").val(data);
        window.form1.submit();
    }
    /**
     * 将二维数组转为 json 字符串
     */
    function arrayToJson(o) {
        var r = [];
        if (typeof o == "string") return "\"" + o.replace(/([\'\"\\])/g, "\\$1").replace(/(\n)/g, "\\n").replace(/(\r)/g, "\\r").replace(/(\t)/g, "\\t") + "\"";
        if (typeof o == "object") {
            if (!o.sort) {
                for (var i in o)
                    r.push(i + ":" + arrayToJson(o[i]));
                if (!!document.all && !/^\n?function\s*toString\(\)\s*\{\n?\s*\[native code\]\n?\s*\}\n?\s*$/.test(o.toString)) {
                    r.push("toString:" + o.toString.toString());
                }
                r = "{" + r.join() + "}";
            } else {
                for (var i = 0; i < o.length; i++) {
                    r.push(arrayToJson(o[i]));
                }
                r = "[" + r.join() + "]";
            }
            return r;
        }
        return o.toString();
    }

    //详情
    function detail(id,bid,sid) {
        window.location.href = "{:url('index/postbusiness/applydetail')}?pid="+id+"&bid="+bid+"&sid="+sid;
    }
    //全部显示
    function res(bid,sid) {
        window.location.href = "{:url('index/postbusiness/product')}?bid="+bid+"&sid="+sid;
    }
</script>
</html>